import { ProFormOptions } from '@/components/pro-form/type'
import { FixModel } from '@/api/model/fix-model'
import { Ref } from 'vue'
import { optionsType } from '~/types/form'

type Props = {
  handleType: Ref<'add' | 'edit' | 'check'>
  typeOptions: Ref<any>
  typeLoading: Ref<boolean>
  budgetOptions: Ref<any>
  budgetLoading: Ref<boolean>
}

export const useFixProForm = ({
  handleType,
  typeOptions,
  typeLoading,
  budgetOptions,
  budgetLoading
}: Props) => {
  const [fixForm, resetFixForm] = useProRef<Partial<FixModel>>({})

  const fixFormOptions = computed<ProFormOptions>(() => {
    const list = [
      {
        formType: 'input',
        key: 'fixCode',
        label: '维修编号',
        disabled: true
      },
      {
        formType: 'input',
        key: 'assetCode',
        label: '资产编号',
        disabled: handleType.value !== 'add'
      },
      {
        formType: 'input',
        label: '资产名称',
        key: 'assetName',
        disabled: true
      },
      {
        formType: 'select',
        key: 'fixType',
        label: '维修状态',
        disabled: true,
        options: useDictData('FIX_STATUS').value
      },
      {
        formType: 'select',
        key: 'fixTypeId',
        label: '资产类型',
        options: typeOptions.value,
        loading: typeLoading.value,
        disabled: true
      },
      {
        formType: 'input',
        key: 'receivePerson',
        label: '申请人',
        disabled: true
      },
      {
        formType: 'input',
        key: 'receiveBranch',
        label: '申请部门',
        disabled: true
      },
      {
        formType: 'date',
        key: 'receiveDate',
        label: '申请日期',
        disabled: true
      },
      {
        formType: 'inputNumber',
        min: 0,
        precision: 2,
        key: 'estimatedCost',
        label: '预估费用',
        noRule: true
      },
      {
        formType: 'textarea',
        key: 'errorDescription',
        label: '故障描述',
        rows: 1,
        gridItem: {
          span: 1
        }
      },
      {
        formType: 'input',
        key: 'fixReason',
        label: '维修原因'
      },
      {
        formType: 'textarea',
        key: 'remark',
        label: '备注',
        gridItem: {
          span: 2
        },
        placeholder: '请输入备注',
        noRule: true
      }
      // {
      //   formType: 'textarea',
      //   key: 'reason',
      //   label: '批复',
      //   gridItem: {
      //     span: 2
      //   },
      //   noRule: true,
      //   disabled: true
      // }
    ] as optionsType
    return handleType.value === 'add'
      ? useSetOptions(list.filter((item) => !item.disabled))
      : useSetOptions(list)
  })

  return {
    fixForm,
    fixFormOptions,
    resetFixForm
  }
}
